package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface UserMapper {

/*
* 根据openid获取用户
* */
    @Select("select * from user where openid=#{openId}")
    User getByOpenId(String openId);

    /*
    * 添加用户
    * */
    @Insert("insert into user\n" +
            "values (null, #{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void save(User user);

    @Select("select * from user where id=#{userId}")
    User getById(Long userId);

    /*
    * 根据动态条件，来统计用户数量
    *  */
    Integer countByMap(Map map);

}
